#include "songlist.h"

#include <QtGui>
#include "ktv/model/resource/resource.h"
#include "ktv/ktv.h"
#include "ktv/gui/listitem/requestsong.h"

SongList::SongList(KTV *k, int w, int h, QList<MyItem *> *songs)
    : MyList(k, w, h, songs)
{
    backgroundPixmap = Resource::getInstance()->backgroundPixmap_songList;
    requestSong = new RequestSong(this);
    requestSong->setPos(0, 0);
    requestSong->setVisible(false);
}

void SongList::selectCurrentItem()
{
    requestSong->setVisible(true);
    requestSong->setPos(0, 0);
    requestSong->setText(currentItem->data(MyList::NAME).toString());

    QPropertyAnimation *animation = new QPropertyAnimation(requestSong, "pos");
    animation->setDuration(2000);
    animation->setEasingCurve(QEasingCurve::InOutSine);
    animation->setStartValue(QPointF(0, 0));
    animation->setEndValue(QPointF(650, 500));
    animation->start();

    ktv->requestSong(currentItem);
}

void SongList::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);
    painter->drawPixmap(-width/2, -height/2, width, height, *backgroundPixmap);
}
